SNOW-1814204 Use fair lock to ensure granting sequence #911
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We should make sure that the long waiting thread get the lock. Otherwise, client’s later insertRow request with later offset token may come and get the lock first -- it will get the earlier internal continuation token and insert first. This could cause issues when incident happens and customer trying to replay the data. This may also cause the data ingested not in sequence.
We should use the fair synch lock to make sure that the thread with the longest waiting time (come earlier) wins and get the lock. Doc for the ReentrantLock: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/ReentrantLock.html